<?php 


namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Request;
use app\admin\controller\Admin;
use think\Paginator;

/**
* 
*/
class Service extends Admin
{
    /**
     * [index 加载首页]
     */
    public function index()
    {
        $list = db('_service_team_information')
            ->paginate(5);
        //echo db('_service_team_information,dj_safety_fee')->getLastSql();die;
        //var_dump($list);die;
        return view('admin@service/index',[
            'service' => $list
        ]);
    }

    /**
     * [addservice 加载添加劳务页面]
     */
    public function addservice()
    {
        //var_dump($res);die;
        return view('admin@service/addservice');
    }



    /**
     * [doadd 执行添加劳务]
     */
    public function doadd()
    {
        $res = input('param.');
        $res['status'] = '0';

        //var_dump($res);die;

        $result = db('_service_team_information')
                  ->insert($res);
        //var_dump($result);
        //var_dump($user->id);
        if ($result > 0) {
            return $this->success('添加成功!', url('admin/service/index'));
        } else {
            return $this->error('添加失败!');
        }

    }


    /**
     * [edit 加载劳务页面]
     */
    public function edit()
    {
        $p = input('param.');
        //var_dump($p);die;
        $id = $p['id'];
        $res = db('_service_team_information')->field(['id','project_name','service_team_name','user_num','special_personnel_num','machines_record','labor_subcontract','status'])->find($id);
        //var_dump($res);die;
        return view('admin@service/edit',[
            'res' => $res
        ]);
    }


    /**
     * [doedit 执行劳务]
     */
    public function doedit()
    {
        $p = input('param.');
        //var_dump($p);die;
        $id = $p['id'];
        $result = db('_service_team_information')->where('id='.$id)->update($p);
        //var_dump($res);die;
        if ($result > 0) {
            return $this->success('编辑成功!', url('admin/service/index'));
        } else {
            return $this->error('你未修改任何内容');
        }
    }


    /**
     * [dostatus 执行劳务]
     */
    public function dostatus()
    {
        $p = input('param.');
        //var_dump($p);die;
        $id = $p['id'];
        $status = db('_service_team_information')->field('status')->where('id='.$id)->find();
        $status['status'] = $status['status'] == 1?0:1;
        $result = db('_service_team_information')->where('id='.$id)->update($status);
        //var_dump($result);die;
        $list = db('_service_team_information')
            ->paginate(5);
        //echo db('_service_team_information,dj_safety_fee')->getLastSql();die;
        //var_dump($list);die;
        return view('admin@service/index',[
            'service' => $list
        ]);
    }


    /**Ajax 删除
     * [delete 执行安全计划删除]
     */
    public function delete($id)
    {
        $result = db('_service_team_information')->delete($id);
        // var_dump($result); exit;
        if ($result > 0) {
            $info['status'] = true;
            $info['id'] = $id;
            $info['info'] = 'ID为:'.$id.'的劳务信息删除成功!';
        } else {
            $info['status'] = false;
            $info['id'] = $id;
            $info['info'] = 'ID为:'.$id.'的劳务信息删除失败!';
        }

        return json($info);
    }

    public function _empty(Request $request)
    {
        return view('/error');
    }








}

 ?>